package cn.bluethink.eguan.core.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.bluethink.eguan.core.security.Token;
import cn.bluethink.eguan.core.service.EgActionService;
import cn.bluethink.eguan.filter.ActionFilter;
import cn.bluethink.eguan.model.core.EgAction;
import cn.bluethink.eguan.result.PageInfo;
import cn.bluethink.eguan.result.ResponseMessage;
import cn.bluethink.eguan.result.ResponseResult;

/**
 * 用户操作对象的动作控制器
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.2.0
 * @brief 驿馆+（EGUAN）
 * @note 修订历史：
 * 1、wanglei于2018/11/09设计并构建初始版本v0.2.0
 */
@CrossOrigin
@RestController
@RequestMapping("/eguan/v1.0/action")
public class EgActionController { 
    
    @Autowired
    private HttpServletRequest request;
    
    @Autowired
    private EgActionService actionService;
    
    /**
     * 过滤查询动作
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/query")
    public ResponseResult<PageInfo<EgAction>> query(@RequestBody ActionFilter filter) throws Exception {
        return new ResponseResult<>(ResponseMessage.OK, actionService.query(filter));
    }
    
    /**
     * 过滤查询动态(用户只能看到所属驿馆伙计的动态)。
     * 筛选项： 如果登录用户拥有查看天眼权限，应该查询所有驿馆列表；否则，只查询当前用户所在驿馆列表
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/dynamic")
    public ResponseResult<PageInfo<EgAction>> dynamic(@RequestBody ActionFilter filter) throws Exception {
        Long uid = (Long) request.getAttribute("userId");
        return new ResponseResult<>(ResponseMessage.OK, actionService.dynamic(filter,uid));
    }
}
